//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.Common;

import javax.management.*;
import java.lang.management.ManagementFactory;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

public class Counter implements DynamicMBean {
    private ConcurrentMap<String, AtomicLong> mapcount = new ConcurrentHashMap();

    public void increment(String name) {
        AtomicLong first = new AtomicLong(1L);
        AtomicLong exist = (AtomicLong)this.mapcount.putIfAbsent(name, first);
        if (exist != null) {
            exist.incrementAndGet();
        }

    }

    public void increment(String name, int delta) {
        AtomicLong first = new AtomicLong((long)delta);
        AtomicLong exist = (AtomicLong)this.mapcount.putIfAbsent(name, first);
        if (exist != null) {
            exist.addAndGet((long)delta);
        }

    }

    public AtomicLong get(String name) {
        return (AtomicLong)this.mapcount.get(name);
    }

    public void set(String name, long value) {
        AtomicLong first = new AtomicLong(value);
        AtomicLong exist = (AtomicLong)this.mapcount.putIfAbsent(name, first);
        if (exist != null) {
            exist.set(value);
        }

    }

    public Object getAttribute(String name) {
        return this.mapcount.get(name);
    }

    public AttributeList getAttributes(String[] attributeNames) {
        AttributeList alist = new AttributeList();

        for(int i = 0; i < attributeNames.length; ++i) {
            Object value = this.getAttribute(attributeNames[i]);
            alist.add(new Attribute(attributeNames[i], value));
        }

        return alist;
    }

    public void setAttribute(Attribute attribute) {
    }

    public AttributeList setAttributes(AttributeList attributes) {
        return null;
    }

    public Object invoke(String operationName, Object[] params, String[] signature) throws MBeanException, ReflectionException {
        return null;
    }

    public MBeanInfo getMBeanInfo() {
        MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[this.mapcount.size()];
        int i = 0;

        String attri;
        for(Iterator var4 = this.mapcount.keySet().iterator(); var4.hasNext(); attributes[i++] = new MBeanAttributeInfo(attri, "java.lang.Long", attri, true, false, false)) {
            attri = (String)var4.next();
        }

        return new MBeanInfo(this.getClass().getName(), "Counter", attributes, (MBeanConstructorInfo[])null, (MBeanOperationInfo[])null, (MBeanNotificationInfo[])null);
    }

    public Counter(String type) {
        try {
            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            server.registerMBean(this, new ObjectName("Counter:type=" + type));
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }
}
